// 定义初始数据
const initProps = {
  activeId: 0,
  list: [] as Channels[],
  AllList: [] as Channels[],
}

export type Channels = {
  id: number
  name: string
}

// 定义 action 数据类型
export type ChannelAction =
  | { type: 'channel/savaList'; payload: Channels[] }
  | { type: 'channel/savaAllList'; payload: Channels[] }
  | { type: 'channel/changeActiveId'; payload: number }

export function channelReducer(state = initProps, action: ChannelAction) {
  switch (action.type) {
    case 'channel/savaList':
      return { ...state, list: action.payload }
    case 'channel/savaAllList':
      return { ...state, AllList: action.payload }
    case 'channel/changeActiveId':
      return { ...state, activeId: action.payload }
    default:
      return state
  }
}
